From 431787af0c63bf26ba30a51faf742f42dcd842e4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20H=C3=A4rdeman?= Date: Sun, 5 Oct 2025 11:52:36 +0200 Subject: [PATCH] rpcd-mod-luci,luci-mod-network: suggest DUID%IAID values MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change the getDUIDHints RPC method to return "DUID%IAID" hints (if the IAID is known, which it is with odhcpd). Use the complete hints in luci-mod-network. Signed-off-by: David Härdeman --- libs/rpcd-mod-luci/src/luci.c | 35 +++++++++++-------- .../resources/view/network/dhcp.js | 5 +-- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/libs/rpcd-mod-luci/src/luci.c b/libs/rpcd-mod-luci/src/luci.c index 7cb56ae2af..d030d43a74 100644 --- a/libs/rpcd-mod-luci/src/luci.c +++ b/libs/rpcd-mod-luci/src/luci.c @@ -1830,29 +1830,27 @@ rpc_luci_get_duid_hints(struct ubus_context *ctx, struct ubus_object *obj, if (lease->af != AF_INET6 || lease->duid == NULL) continue; - e = avl_find_element(&avl, lease->duid, e, avl); + size_t key_len = strlen(lease->duid) + 1 + (lease->iaid ? strlen(lease->iaid) + 1 : 0); + char key[key_len]; + sprintf(key, "%s%s%s", lease->duid, + lease->iaid ? "%" : "", + lease->iaid ? lease->iaid : ""); + + e = avl_find_element(&avl, key, e, avl); if (e) continue; - e = calloc_a(sizeof(*e), &p, strlen(lease->duid) + 1); - + e = calloc_a(sizeof(*e), &p, key_len); if (!e) continue; - o = blobmsg_open_table(&blob, lease->duid); + o = blobmsg_open_table(&blob, key); - inet_ntop(AF_INET6, &lease->addr[0].in6, s, sizeof(s)); - blobmsg_add_string(&blob, "ip6addr", s); + blobmsg_add_string(&blob, "duid", lease->duid); - a = blobmsg_open_array(&blob, "ip6addrs"); - - for (n = 0; n < lease->n_addr; n++) { - inet_ntop(AF_INET6, &lease->addr[n].in6, s, sizeof(s)); - blobmsg_add_string(&blob, NULL, s); - } - - blobmsg_close_array(&blob, a); + if (lease->iaid) + blobmsg_add_string(&blob, "iaid", lease->iaid); if (lease->hostname) blobmsg_add_string(&blob, "hostname", lease->hostname); @@ -1860,9 +1858,16 @@ rpc_luci_get_duid_hints(struct ubus_context *ctx, struct ubus_object *obj, if (!ea_empty(&lease->mac)) blobmsg_add_string(&blob, "macaddr", ea2str(&lease->mac)); + a = blobmsg_open_array(&blob, "ip6addrs"); + for (n = 0; n < lease->n_addr; n++) { + inet_ntop(AF_INET6, &lease->addr[n].in6, s, sizeof(s)); + blobmsg_add_string(&blob, NULL, s); + } + blobmsg_close_array(&blob, a); + blobmsg_close_table(&blob, o); - e->avl.key = strcpy(p, lease->duid); + e->avl.key = strcpy(p, key); avl_insert(&avl, &e->avl); } diff --git a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/dhcp.js b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/dhcp.js index 14ae192cb0..89c17ff46c 100644 --- a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/dhcp.js +++ b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/dhcp.js @@ -874,8 +874,9 @@ return view.extend({ _('Syntax: <DUID-hex-str> or <DUID-hex-str>%<IAID-hex-str>')); so.rmempty = true; so.validate = validateDUIDIAID; - Object.keys(duids).forEach(function(duid) { - so.value(duid, '%s (%s)'.format(duid, duids[duid].hostname || duids[duid].macaddr || duids[duid].ip6addr || '?')); + Object.keys(duids).forEach(function(duid_iaid) { + var desc = duids[duid_iaid].hostname || duids[duid_iaid].macaddr || duids[duid_iaid].ip6addrs[0] || '?'; + so.value(duid_iaid, '%s (%s)'.format(duid_iaid, desc)); }); so = ss.option(form.Value, 'hostid', -- 2.30.2